home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / dd / rexxfunc.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  6KB  |  249 lines

  1. /*
  2.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  3.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  4.  *    DICE-LICENSE.TXT.
  5.  */
  6. #include    "defs.h"
  7. #include    "dbug_protos.h"
  8.  
  9.  
  10. Prototype BOOL        RXGetPC(char *args);
  11. Prototype BOOL        RXGetLine(char *args);
  12. Prototype BOOL        RXGetInfo(char *args);
  13. Prototype BOOL        RXGetDismLine(char *args);
  14. Prototype BOOL         RXGetEval(char *args);
  15. Prototype BOOL         RXGetBytes(char *args);
  16. Prototype BOOL        RXGetWords(char *args);
  17. Prototype BOOL        RXGetLongs(char *args);
  18.  
  19. Prototype BOOL        RXGetCommand(char *args);
  20.  
  21. Prototype BOOL        RXStartList(char *args);
  22. Prototype BOOL        RXEndList(char *args);
  23. Prototype BOOL        RXPutList(char *args);
  24.  
  25.  
  26.  
  27. BOOL    RXGetPC(char *args)
  28. {
  29.     sprintf(RexxReplyString, "%08X",programPC);
  30.     return TRUE;
  31. }
  32.  
  33.  
  34.  
  35. BOOL    RXGetEval(char *args) {
  36. long val;
  37. short undef = TRUE;
  38.  
  39.  
  40.     if(*args) {
  41.         val = ParseExp(args, &undef, strlen(args));
  42.     }
  43.     if(!undef) {
  44.     char    buf[128];
  45.         OffsetAddressBuf(val, buf);
  46.     sprintf(RexxReplyString,"%d %08lx  %s",val, val, buf);
  47.     return TRUE;
  48.     }
  49.     sprintf(RexxReplyString,"UNDEFINED");
  50.     return 0;
  51. }
  52.  
  53.  
  54. BOOL    RXGetLine(char *args) {
  55. ULONG addr, line = 0;
  56. long    info[2];    //    info[0] == lineBeg, info[1] == lineNo
  57. WORD type, i;
  58. short undef = TRUE;
  59.  
  60.  
  61.     if(*args) {
  62.         addr = ParseExp(args, &undef, strlen(args));
  63.     }
  64.     if(undef)addr = programPC;
  65.     type = CurrentMixedLine(&addr, &line, info);
  66.     if(type == MIXTYPE_SOURCE) {
  67.     char *lineStr = (char *)info[0];
  68.     for (i = 0; lineStr[i] && lineStr[i] != '\n'; ++i)
  69.         ;
  70.         sprintf(RexxReplyString,"%6d. ", info[1]); 
  71.     strncat(RexxReplyString, lineStr, i);
  72.     }
  73.     else {
  74.     sprintf(RexxReplyString,"%08X",addr);
  75.     strcat(RexxReplyString," ");
  76.     i=strlen(RexxReplyString);
  77.     Disassemble(addr, addr, &RexxReplyString[i]);
  78.     }
  79.     return TRUE;
  80. }
  81.  
  82. BOOL    RXGetDismLine(char *args) {
  83. ULONG addr;
  84. short undef = TRUE, i;
  85.  
  86.  
  87.     if(*args) {
  88.         addr = ParseExp(args, &undef, strlen(args));
  89.     }
  90.     if(undef)addr = programPC;
  91.     sprintf(RexxReplyString,"%08X",addr);
  92.     strcat(RexxReplyString," ");
  93.     i=strlen(RexxReplyString);
  94.     Disassemble(addr, addr, &RexxReplyString[i]);
  95.     return TRUE;
  96. }
  97.  
  98. BOOL    RXGetBytes(char *args) {
  99. ULONG addr;
  100. UBYTE    *address;
  101. short undef = TRUE, i = 0, j;
  102.  
  103.  
  104.     if(*args) {
  105.         addr = ParseExp(args, &undef, strlen(args));
  106.     }
  107.     if(undef)addr = programPC;
  108.     address = (UBYTE *)addr;
  109.     for (i = 0; i < 7; ++i) {
  110.     j=strlen(RexxReplyString);
  111.     sprintf(&RexxReplyString[j]," %02X", address[i]);
  112.     }
  113.     return TRUE;
  114. }
  115.  
  116.  
  117. BOOL    RXGetLongs(char *args) {
  118. ULONG addr;
  119. UBYTE    *address;
  120. short undef = TRUE, i = 0, j;
  121.  
  122.  
  123.     if(*args) {
  124.         addr = ParseExp(args, &undef, strlen(args));
  125.     }
  126.     if(undef)addr = programPC;
  127.     address = (UBYTE *)addr;
  128.     for (i = 0; i < 7*4; i += 4) {
  129.     j =strlen(RexxReplyString);
  130.     sprintf(&RexxReplyString[j]," %08X", (address[i] << 24) | (address[i+1] << 16) | (address[i+2] << 8) | address[i+3]);
  131.     }
  132.     return TRUE;
  133. }
  134.  
  135. BOOL    RXGetWords(char *args) {
  136. ULONG addr;
  137. UBYTE    *address;
  138. short undef = TRUE, i = 0, j;
  139.  
  140.  
  141.     if(*args) {
  142.         addr = ParseExp(args, &undef, strlen(args));
  143.     }
  144.     if(undef)addr = programPC;
  145.     address = (UBYTE *)addr;
  146.     for (i = 0; i < 7*2; i += 2) {
  147.     j =strlen(RexxReplyString);
  148.     sprintf(&RexxReplyString[j]," %04X", (address[i] << 8) | address[i+1]);
  149.     }
  150.     return TRUE;
  151. }
  152.  
  153.  
  154. // RXGetCommand
  155.  
  156. BOOL RXGetCommand(char *args) {
  157.  
  158.     commandLine[commandEnd] = '\0';
  159.     strcpy(RexxReplyString,commandLine);
  160.     InitCommand();        // necessary to clear command line
  161.     ScrCursoff();
  162.     RefreshCommand(1);
  163.     ScrCurson();
  164.  
  165.     return TRUE;
  166.  
  167.  
  168. }
  169.  
  170. /* RxGetInfo function
  171.  * returns a string in the following format
  172.  * breakpoint status   program state
  173.  * source file name (or NOSOURCE)   address range for source
  174.  * line number range for source
  175.  *
  176.  */
  177. BOOL    RXGetInfo(char *args) {
  178. ULONG addr, line = 0, startaddr, endaddr;
  179. long    info[2];    //    info[0] == lineBeg, info[1] == lineNo
  180. int first = 0, last = 0, type;
  181. short undef = TRUE, i;
  182. DEBUG    *debug;
  183.  
  184.     if(*args) {
  185.         addr = ParseExp(args, &undef, strlen(args));
  186.     }
  187.     if(undef)addr = programPC;
  188.     debug = FindNearestDebug(addr);
  189.  
  190.     // give breakpoint info and program status first
  191.     if(IsBreakpoint(addr))sprintf(RexxReplyString,"BP ");
  192.     sprintf(RexxReplyString,"NOBP ");
  193.  
  194.     strcat(RexxReplyString,StateText(programState));
  195.  
  196.     if(debug) {    // we have source
  197.  
  198.         // find end of this source range
  199.         type = CurrentMixedLine(&addr,&line,info);
  200.     if (type == 0)type = NextMixedLine(&addr, &line, info);
  201.  
  202.         if(type == MIXTYPE_SOURCE) {
  203.         first = info[1];
  204.         // find end of range for the target range
  205.         while(NextMixedLine(&addr,&line,info) == MIXTYPE_SOURCE);
  206.         last = info[1];
  207.     }
  208.  
  209.     // now find the address range for this line
  210.     startaddr = endaddr = addr;
  211.     while(NextMixedLine(&addr,&line,info) == MIXTYPE_DISM)endaddr=addr;
  212.  
  213.     // give source range, then address range
  214.     i = strlen(RexxReplyString);
  215.     sprintf(&RexxReplyString[i]," %d. %d. %08X %08X",first,last,startaddr,endaddr);
  216.  
  217.     // finally, give the file name
  218.     strcat(RexxReplyString," ");
  219.     strcat(RexxReplyString,DirBuf);
  220.     strcat(RexxReplyString,debug->sourceName);
  221.     }
  222.     else {
  223.     strcat(RexxReplyString," NOSOURCE 0. 0. 0 0 NOSOURCE"); 
  224.     }
  225.     return TRUE;
  226. }
  227.  
  228. // Arexx List building commands
  229. BOOL    RXStartList(char *args) {
  230.     LIST    *lp = &CurDisplay->ds_List;
  231.  
  232.     FreeDLIST(lp);
  233.     SetDisplayMode(DISPLAY_REXXLIST,0);
  234.  
  235.     return TRUE;
  236. }
  237.  
  238. BOOL    RXEndList(char *args) {
  239.  
  240.     SetDisplayMode(DISPLAY_REXXLIST,0);
  241.     RefreshWindow(TRUE);
  242.     return TRUE;
  243. }
  244.  
  245. BOOL    RXPutList(char *args) {
  246.     SprintfDLIST(&CurDisplay->ds_List, DTYPE_REXXLIST, "%s", args);
  247.     return TRUE;
  248.  
  249. }